package com.hbean.controller;

import com.hbean.service.SysAccService;
import com.hbean.system.annotation.LogMethod;
import com.hbean.system.config.Base;
import com.hbean.utils.HUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description: null
 * @Project: hbean
 * @Author: hjibo
 * @CreateDate: 2018/10/26 11:56
 * @ModificationHistory: （who whatTime doWhat）
 */

@Slf4j
@RestController
@RequestMapping("/sysAcc")
public class SysAccController extends Base{

    @Autowired
    private SysAccService sysAccService;

    /**
     * description: 新增
     * create_user: hjibo
     * create_date: 2018-09-29 10:19
     * param :
     */
    @RequestMapping("/addAcc")
    @LogMethod(logName = "新增附件")
    public Map addAcc(HttpServletRequest request){

        String fjIds = null;//返回的附加你的id
        try {
            // 获取前台传值
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            fjIds = this.sysAccService.addAccessory(multipartRequest);
            return mapResult(SUCCESS_CODE,SUCCESS_MSG,LONG_0L,fjIds);
        } catch (Exception e) {
            log.info("保存附件信息失败！");
            e.printStackTrace();
        }
        return mapResult(ERROR_CODE,ERROR_MSG,LONG_0L,null);
    }

    /**
     * description: 回显头像
     * create_user: hjibo
     * create_date: 2018-09-29 10:19
     * param :
     */
    @RequestMapping("/getPhoto")
    public byte[] getPhoto(HttpServletRequest request){

        String filePath = null;
        try {
            filePath = request.getParameter("filePath");
        } catch (Exception e) {
            log.info("回显头像失败！");
            e.printStackTrace();
        }
        return HUtil.fileToBytes(filePath);
    }


}
